<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">会员提现申请表</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!home">首页</a>
          <a><cite>会员提现申请表</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
                      搜索：  <select id="membercashapply-search-key">
            <option value="">-请选择-</option>
                 <option value="id">ID</option>
                 <option value="member_id">会员ID</option>
                 <option value="check_user_id">审核人ID</option>
                 <option value="cash_user_id">转账人ID</option>
                 <option value="apply_user_id">申请人ID</option>
                 <option value="cash_amount">转账金额</option>
                 <option value="charge_fee">手续费</option>
                 <option value="actual_amount">实际到账</option>
                 <option value="status">状态，1-待审核，2-已审核，3-已转帐， -1-驳回</option>
                 <option value="cash_style">提现方式，1-线下，2-到微信钱包，3-到银行卡</option>
                 <option value="description">说明</option>
                 <option value="create_date">创建时间</option>
                 <option value="check_date">审核时间</option>
                 <option value="cash_date">转账时间</option>
                 </select>&emsp;
            <input id="membercashapply-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="membercashapply-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="membercashapply-table" lay-filter="membercashapply-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="membercashapply-table-bar">
 {{#   if(admin.hasPerm("member:membercashapply:update") ){   }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
 {{#     } }}
 {{#   if(admin.hasPerm("member:membercashapply:update") ){   }}
 <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="check">审核</a>
 {{#     } }}
 {{#   if(admin.hasPerm("member:membercashapply:update") ){   }}
 <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="reject">驳回</a>
 {{#     } }}
 {{#   if(admin.hasPerm("member:membercashapply:update") ){   }}
 <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="pay">支付</a>
 {{#     } }}
 <!--{{#  if(admin.hasPerm("member:membercashapply:delete") ){   }}-->
    <!--<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>-->
 <!--{{#     } }} -->

</script>


<!--<script type="text/html" id="toolbar">-->
     <!--{{#  if(admin.hasPerm("member:membercashapply:save")){ }}-->
     <!--<button id="membercashapply-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>-->
     <!--{{#     } }} -->
 <!---->
<!--</script>-->

<script type="text/html" id="btstatus">
    {{# if(d.status == 1){ }}
    待审核
    {{# } }}

    {{# if(d.status == 2){ }}
    已审核
    {{# } }}
    {{# if(d.status == 3){ }}
    已转账
    {{# } }}
    {{# if(d.status == -1){ }}
    驳回
    {{# } }}
</script>

<script type="text/html" id="btgetstyle">
    {{# if(d.cashStyle == 1){ }}
    线下支付
    {{# } }}

    {{# if(d.cashStyle == 2){ }}
    微信钱包
    {{# } }}
    {{# if(d.cashStyle == 3){ }}
    银行卡
    {{# } }}
</script>

<script>
   var admin;
    layui.use(['form', 'table', 'util', 'config', 'admin', 'upload','laytpl','element' ], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
          admin = layui.admin;
        //上传
        var upload = layui.upload;
        let laytpl = layui.laytpl;
        let element = layui.element;

        // 渲染表格
        table.render({
            elem: '#membercashapply-table',
            url: config.base_server + 'member/membercashapply/listforweb',
            method: 'GET',
       
            page: true,
            cols: [[
                {type: 'numbers'},
                           // {field: 'id', sort: true, title: 'ID'},
                           // {field: 'memberId', sort: true, title: '会员ID'},
                           {field: 'checkUsername', sort: false, title: '审核人'},
                           {field: 'cashUsername', sort: false, title: '转账人'},
                           {field: 'applyUsername', sort: false, title: '申请人'},
                           {field: 'cashAmount', sort: false, title: '转账金额'},
                           {field: 'chargeFee', sort: false, title: '手续费'},
                           {field: 'actualAmount', sort: false, title: '实际到账'},
                           {field: 'status', sort: false, title: '状态',toolbar : 	"#btstatus"},
                           {field: 'cashStyle', sort: false, title: '提现方式',toolbar:"#btgetstyle"},
                           {field: 'description', sort: false, title: '说明'},
                           {field: 'createDate', sort: false, title: '创建时间'},
                           {field: 'checkDate', sort: false, title: '审核时间'},
                           {field: 'cashDate', sort: false, title: '转账时间'},
                        
                {fixed: 'right', align: 'center', toolbar: '#membercashapply-table-bar', title: '操作', width: 175}
            ]]
        });
        
        // laytpl($("#toolbar")[0].innerHTML).render({ }, function(html){
		// 	  $(".layui-card-body .toolbar").append(html);
		// 	  element.render('nav');
		//   });

        // 添加按钮点击事件
        $('#membercashapply-btn-add').click(function () {
            showEditModel();
        });

        // 工具条点击事件
        table.on('tool(membercashapply-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            console.log("data list...");
// console.log(obj);
            if (layEvent === 'edit') { // 修改
             
                showEditModel(data);
            } else if(layEvent === 'check'){
                layer.confirm('确定通过审核吗？', function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('member/membercashapply/pass/'+obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 500});
                            table.reload('membercashapply-table', {});
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 500});
                        }
                    }, 'POST');
                });
            } else if(layEvent === 'reject'){
                layer.confirm('确定驳回申请吗？', function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('member/membercashapply/reject/'+obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 500});
                            table.reload('membercashapply-table', {});
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 500});
                        }
                    }, 'POST');
                });
            }else if(layEvent === 'pay'){
                layer.confirm('确定已转账了吗？', function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('member/membercashapply/pay/'+obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 500});
                            table.reload('membercashapply-table', {});
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 500});
                        }
                    }, 'POST');
                });
            }else if (layEvent === 'del') { // 删除
                layer.confirm('确定删除吗？', function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('member/membercashapply/delete/'+obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 500});
                            table.reload('membercashapply-table', {});
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 500});
                        }
                    }, 'delete');
                });
            }
        });

        //显示表单弹窗
        var showEditModel = function (data) {
        	  var title = data ? '修改用户' : '添加用户';
            //修改方法名
            if (data){
                data.method="update"
            }else{
            	data={method:"save"};
            }
 
            admin.putTempData('t_membercashapply', data);
            admin.popupCenter({
                title: title,
                path: 'pages/member/membercashapply_form.html',
                finish: function () {
                    table.reload('membercashapply-table', {});
                }
            });
        };

        // 搜索按钮点击事件
        $('#membercashapply-btn-search').click(function () {
            var key = $('#membercashapply-search-key').val();
            var value = $('#membercashapply-search-value').val();
            table.reload('membercashapply-table', {where: {searchKey: key, searchValue: value}});
        });

    });
</script>
